package com.seedwill.common.meta.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;

import com.seedwill.common.meta.IData;
import com.seedwill.common.meta.IEvent;
import com.seedwill.common.meta.IIdentity;

public abstract class ABaseEventObject extends EventObject implements IEvent {
	
	public ABaseEventObject(Object source) {
		super(source);
	}

	protected List<IData> childDataList;

	protected List<IIdentity> aspectList;
	
	protected IData parentData;
	
	protected Object data;

	protected String wildCatetory;

	protected Object meta;

	@Override
	public void addChildData(IData childData) {
		if (childDataList == null) {
			childDataList = new ArrayList<IData>();
		}
		childDataList.add(childData);
	}

	@Override
	public void cleanChildData() {
		if (childDataList != null) {
			childDataList.clear();
		}
	}

	@Override
	public IData getSclarAspect(IIdentity aspectIdt) {
		if (aspectList != null) {
			for (IIdentity d : aspectList) {
				if (d.getIdentityVal().equals(aspectIdt.getIdentityVal())
						&& aspectIdt.getMeta().equals(d.getMeta())) {
					return d;
				}
			}
		}
		return null;
	}

	public List<IData> getAspect(IIdentity aspectIdt) {
		List<IData> aspectL = null;
		if (aspectList != null) {
			aspectL = new ArrayList<IData>();
			for (IIdentity d : aspectList) {

				if (d.according(aspectIdt)) {
					aspectL.add(d);
				}
			}
		}
		return aspectL;
	}

	@Override
	public Object getData() {
		return data;
	}

	@Override
	public String getWildCatetory() {
		return wildCatetory;
	}

	@Override
	public void removeChildData(IData childData) {
		if (childDataList != null) {
			childDataList.remove(childData);
		}
	}

	@Override
	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public void setWildCatetory(String cate) {
		this.wildCatetory = cate;
	}

	@Override
	public Object getMeta() {
		// TODO Auto-generated method stub
		return meta;
	}

	@Override
	public void setMeta(Object meta) {
		this.meta = meta;
	}

	protected String identityName;
	protected IData identityVal;
	protected Serializable serializableIdentity;

	@Override
	public boolean according(IIdentity another) {
		if (this.getMeta().equals(another.getMeta())
				&& this.getIdentityVal().equals(another.getIdentityVal())) {
			return true;
		}
		return false;
	}

	@Override
	public String getIdentityName() {
		return identityName;
	}

	@Override
	public IData getIdentityVal() {
		// TODO Auto-generated method stub
		return identityVal;
	}

	@Override
	public Serializable getSerializableIdentity() {
		// TODO Auto-generated method stub
		return serializableIdentity;
	}

	public IData getParentData() {
		return parentData;
	}

	public void setParentData(IData parentData) {
		this.parentData = parentData;
	}
}
